{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "利用numpy中eigh函数，求得的哈密顿量全部能谱 = \n",
      "[-0.75  0.25  0.25  0.25]\n",
      "\n",
      "利用scipy中eigsh函数，求得的哈密顿量基态能 = \n",
      "[-0.75]\n",
      "\n",
      "利用基态算法，求得的哈密顿量基态能 = \n",
      "[-0.75]\n",
      "\n",
      "利用scipy中eigsh函数，求得的哈密顿量基态 = \n",
      "[-1.92217103e-17 -7.07106781e-01  7.07106781e-01  1.11149644e-17]\n",
      "\n",
      "利用基态算法，求得的哈密顿量基态 = \n",
      "[-2.10098802e-13 -7.07106781e-01  7.07106781e-01 -1.19552288e-13]\n"
     ]
    }
   ],
   "source": [
    "import BasicFun as bf\n",
    "import numpy as np\n",
    "from scipy.sparse.linalg import eigsh\n",
    "\n",
    "# 相关函数在BasicFun.py文件定义\n",
    "\n",
    "# 定义二自旋反铁磁海森堡模型\n",
    "H2 = bf.heisenberg_hamilt([1, 1, 1], [0, 0, 0])\n",
    "\n",
    "e1 = np.linalg.eigh(H2)[0]\n",
    "print('利用numpy中eigh函数，求得的哈密顿量全部能谱 = ')\n",
    "print(e1)\n",
    "\n",
    "e2, v2 = eigsh(H2, k=1, which='LM')\n",
    "print('\\n利用scipy中eigsh函数，求得的哈密顿量基态能 = ')\n",
    "print(e2)\n",
    "\n",
    "e0, gs = bf.ED_ground_state([H2.reshape(2, 2, 2, 2)], [[0, 1]])\n",
    "print('\\n利用基态算法，求得的哈密顿量基态能 = ')\n",
    "print(e0)\n",
    "\n",
    "\n",
    "print('\\n利用scipy中eigsh函数，求得的哈密顿量基态 = ')\n",
    "print(v2.reshape(-1, ))\n",
    "print('\\n利用基态算法，求得的哈密顿量基态 = ')\n",
    "print(gs.reshape(-1, ))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
